import { createApp } from "vue";

import { subscribeRouterChange } from "@/hooks/useMicroApp";
import Cookies from "js-cookie";
// import "default-passive-events"; //添加事件管理者passive

import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import locale from "element-plus/lib/locale/lang/zh-cn"; // 中文语言

import "@/assets/styles/index.scss"; // global css
import "@/assets/styles/theme.scss";
import "@/assets/iconfont/iconfont.css"; // iconfont css
import "@/assets/font/font.css";

// svg图标
import "virtual:svg-icons-register";

import App from "./App";
import store from "./store";
import router from "./router";
import directive from "./directive"; // directive

// 注册指令
import plugins from "./plugins"; // plugins

import elementIcons from "@/components/SvgIcon/svgicon";
import "./permission"; // permission control
import "amfe-flexible/index.js";
const app = createApp(App);

app.use(router);
app.use(store);
app.use(plugins);
app.use(elementIcons);
directive(app);

// 使用element-plus 并且设置全局的大小
app.use(ElementPlus, {
	locale: locale,
	// 支持 large、default、small
	size: Cookies.get("size") || "default"
});
app.mixin({
	created() {
		nextTick(() => {
			const pattern =
				/[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2159]|[\u2180-\u2210]|[\u221b-\u2712]|[\u2720-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/gi;
			Array.from(document.getElementsByClassName("el-input__inner")).forEach((input: any) => {
				input.oninput = function (e: any) {
					e.target.value = e.target.value.replace(pattern, "");
				};
			});
			Array.from(document.getElementsByClassName("el-textarea__inner")).forEach((input: any) => {
				input.oninput = function (e: any) {
					e.target.value = e.target.value.replace(pattern, "");
				};
			});
		});
	}
});
app.mount("#app");

subscribeRouterChange();
